package com.ruoyi.common.utils;

import java.util.Random;

/**
 * @Package: com.ruoyi.common.utils
 * @Author: HanWL
 * @CreateTime: 2023-10-19 11:34
 * @Version: 1.0
 **/
public class RandomUtils {

    /**
     * 随机生成一个16位的数字组合
     * @return
     */
    public static String generate16Number() {
        Random random = new Random();
        long randomNumber = Math.abs(random.nextLong() % 9000000000000000L + 1000000000000000L); // 生成一个16位随机数字
        return String.valueOf(randomNumber); // 将随机数字转换为字符串
    }

    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    /**
     * 随机生成一个6位的数字和字母组合
     * @param
     * @return
     */
    public static String generate6Char() {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < 6; i++) {
            int randomIndex = random.nextInt(CHARACTERS.length());
            char randomChar = CHARACTERS.charAt(randomIndex);
            sb.append(randomChar);
        }

        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(generate6Char());
    }
}
